/* 
 * File:   Navigator.h
 * Author: jorge
 *
 * Created on July 26, 2013, 10:24 AM
 */

#ifndef NAVIGATOR_H
#define	NAVIGATOR_H

#include "TrieNode.h"
#include <cctype>

template<class E>
class Navigator
{
public:

    Navigator(TrieNode<E>* node)
    {
        this->node_ = node;
    }

    void setNode(TrieNode<E>* node)
    {
        this->node_ = node;
    }

        Navigator<E> find(const char c, TrieNode<E>* node)
        {
            if(node)
            {
                char key = node->getKey();
                char lowerChar = isupper(c) ? tolower(c) : c;
                key = isupper(key) ? tolower(key) : key;
                if(key == lowerChar)
                {
                    return Navigator(node->getChildren());
                }
                else
                {
                    return find(c, node->getNext());
                }
            }
            else 
            {
                TrieNode<E>* empty = 0;
                return Navigator(empty);
            }
        }

    Navigator<E> find(const char c)
    {
        return find(c, this->node_);
    }

    TrieNode<E>* operator*()
    {
        return this->node_;
    }

private:
    TrieNode<E>* node_;
};

#endif	/* NAVIGATOR_H */

